package com.ideabove.heart;


import java.util.Hashtable;

import com.ideabove.heart.data.CallListAdapter;
import com.ideabove.heart.manager.AppManager;
import com.ideabove.heart.manager.ScheduleManager;
import com.ideabove.heart.manager.SoundManager;
import com.ideabove.heart.util.MyUtil;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ListView;

public class CallListActivity extends MyActivity{

	CallListAdapter adapter;
	ListView callList;
	SoundManager soundMgr;
	int SOUND_IDX = 1;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.call_list);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

		listInit();
		
		AppManager.start();
		
		// 효과음
		soundMgr = new SoundManager(this);
		soundMgr.addSound(SOUND_IDX, R.raw.button_press);
		
		ImageView btn_call_list_confirm = (ImageView)findViewById(R.id.btn_call_list_confirm);
		btn_call_list_confirm.setOnTouchListener(new OnTouchListener(){

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				MyUtil.touchMe(v, event, new MyUtil.ImageTouch() {

					@Override
					public void touch(View v, MotionEvent event) {
						// TODO Auto-generated method stub
						soundMgr.playSound(SOUND_IDX);						
						finish();
						
						Intent intent = new Intent(CallListActivity.this, MainActivity.class);
//						intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
						intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
						startActivity(intent);
					}
				});
				
				return true;
			}
			
		});
		
	}
	
	public void listInit(){			
		ScheduleManager scheMgr = new ScheduleManager(this);
		
		adapter = new CallListAdapter(this,scheMgr.getScheduleInfoList());
		callList = (ListView)findViewById(R.id.call_listv);				
		callList.setAdapter(adapter);
		callList.setDivider(null);		
	}	

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		if(soundMgr != null){
			soundMgr.clear();
		}
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		AppManager.pause(CallListActivity.this);
	}

	@Override
	protected void onDestroy(){
		super.onDestroy();
	}


}
